﻿using System;

namespace WinnerCMS.Common
{
    /// <summary>
    /// 数学公式
    /// </summary>
    public class MyMath
    {

        #region 进一法
        /// <summary>
        /// 两数相除得数用进一法
        /// </summary>
        /// <param name="totalNo">有N行数据</param>
        /// <param name="pageSize">每页显示N行</param>
        /// <returns>分页后有X页</returns>
        public static int GetCeiling(double totalNo, double pageSize)
        {
            return (int)Math.Ceiling(totalNo / pageSize);
        }
        #endregion

        #region 去尾法
        /// <summary>
        /// 去尾法
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        static public int GetInteger(double d)
        {
            string str = d.ToString().Split('.')[0];
            return int.Parse(str);
        }
        #endregion

        /// <summary>
        /// 返回百分比
        /// </summary>
        /// <param name="fenZhi">分子</param>
        /// <param name="fenMu">分母</param>
        /// <returns></returns>
        public static string Percent(int fenZhi, int fenMu)
        {
            decimal d = Convert.ToDecimal(fenZhi) / Convert.ToDecimal(fenMu);

            return Math.Round(d * 100, 4) + " ％";
        }
        /// <summary>
        /// 是否为奇数
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static bool IsOdd(int n)
        {
            return Convert.ToBoolean(n & 1);
        }
    }
}